﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Summary description for VendorMethord
/// </summary>
public class VendorMethord
{
	public VendorMethord()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    SqlConnection sqlcon = Conection.getconnet();
    public void OpenConnect()
        { 
            if(sqlcon.State == System.Data.ConnectionState.Closed)
            {
                sqlcon.Open();
            }
        }
    public DataTable ViewAllOrder() {
        DataTable dt = new DataTable();
        SqlCommand sqlcom = new SqlCommand("ViewAllOrder",sqlcon);
        OpenConnect();
        sqlcom.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        sqlcon.Close();
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
    }
    public DataTable GetUserId(int _id) {
        DataTable dt = new DataTable();
        OpenConnect();
        SqlCommand sqlcom = new SqlCommand("ViewUser",sqlcon);
        sqlcom.Parameters.Add("@OrderID",_id);
        sqlcom.CommandType = CommandType.StoredProcedure;
        sqlcom.ExecuteNonQuery();
        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        sqlcon.Close();
        return dt;
    }
    public DataTable VendorViewAddres(int _OrderID)
    {
        DataTable dt = new DataTable();
        OpenConnect();
        SqlCommand sqlcom = new SqlCommand("ViewAddress",sqlcon);
        sqlcom.Parameters.Add("@OrderId",_OrderID);
        sqlcom.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        sqlcon.Close();
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
    }
    public DataTable VendorViewShippingType() {
        DataTable dt = new DataTable();
        OpenConnect();
        SqlCommand sqlcom = new SqlCommand("VIEWShippingType",sqlcon);
        sqlcom.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
        sqlcon.Close();
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        dt = ds.Tables[0];
        return dt;
    }
    public bool AddShippingDetails(string _fulname, int PhoneNumber, int _OrderId,int _EmId,string _address, int _typeShipping, string _description) {
        bool resurt = false;
        OpenConnect();
        SqlCommand sqlcom = new SqlCommand("ShippingManager", sqlcon);
        sqlcom.Parameters.Add("@FullName", _fulname);
        sqlcom.Parameters.Add("@PhoneNumber", PhoneNumber);
        sqlcom.Parameters.Add("@OrderId", _OrderId);
        sqlcom.Parameters.Add("@EmployeeID", _EmId);
        sqlcom.Parameters.Add("@Address", _address);
        sqlcom.Parameters.Add("@TypeOfShipping", _typeShipping);
        sqlcom.Parameters.Add("@Description", _description);
        sqlcom.CommandType = CommandType.StoredProcedure;
        try
        {
            sqlcom.ExecuteNonQuery();
            resurt = true;
            sqlcon.Close();
        }
        catch (Exception ex)
        {

            sqlcon.Close();
            resurt = false;
        }
        return resurt;
     }
    public bool VendorUpdateOrder(int _id) {
        bool res = false;
        OpenConnect();
        SqlCommand sqlcom = new SqlCommand("VendorChangeOrder",sqlcon);
        sqlcom.Parameters.Add("@OrderId",_id);
        sqlcom.CommandType = CommandType.StoredProcedure;
        try
        {
            sqlcom.ExecuteNonQuery();
            res = true;
        }
        catch (Exception ex)
        {
            res = false;
            sqlcon.Close();
            
        }
        return res;
    }
   
}